(:
  A procedure to select the comments of an atom xml feed
:)
declare boundary-space strip;
import module namespace
    jj = "http://kumquat.emse.fr/utilitaires"
    at "jjutils.xq" ;
declare namespace atom = "http://www.w3.org/2005/Atom";
declare namespace thr = "http://purl.org/syndication/thread/1.0";
<display>{
let $t := $arguments[1] 
let $d := doc($t)/atom:feed/atom:entry

for $entry at $p in $d
let $date := xs:dateTime($entry/atom:published/text())

where $entry/atom:category[@scheme="http://schemas.google.com/g/2005#kind"][@term="http://schemas.google.com/blogger/2008/kind#comment"]
return
let $contents := jj:remove-html($entry/atom:content/text())
return
  <item>{
    <info name="time"><time><date>{xs:string(jj:date-to-millis($date))}</date><duration>0</duration></time></info>,
    <info name="date">{fn:substring(jj:editDate($date),1,10)}</info>,
    <info name="type">comment</info>,
    <info name="src-anchor">{
    <anchor>{
        <doc>{ $t }</doc>,
        <path>{$entry/atom:id/text()}</path>
      }</anchor>
    }</info>,
    <info name="id">{xs:string($entry/atom:id)}</info>,
    <info name="author">{$entry/atom:author/atom:name/text()}</info>,
    <info name="title">{$entry/atom:title/text()}</info>,
    <info name="content">{$contents}</info>,
    <info name="postid">{xs:string($entry/thr:in-reply-to/@ref)}</info>
  }</item>
}</display>
